
{ Macro for drawing a dimension marker on an image    12 Nov 2005	}

macro 'Draw Dimension [D]'

{ draws a pair of parallel lines and arrows separated by }
{ a distance determined from the straight line selection }
{ and labels the separation with the calibrated distance }

var
  x1, y1, x2, y2, LineSize, LineWidth, ArrowLen, ArrowHead:integer;
  ImageScale, d: real;
  ImageUnit: string;

begin
  LineSize := 15;                                                { in pixels }
  ArrowLen := 20;
  ArrowHead := 7;
  
  GetLine(x1, y1, x2, y2, LineWidth);
  
  if x1 < 0 then begin
    beep;
    PutMessage('Use the line tool (straight) to select a line first.');
    exit;
  end;
  
  GetScale(ImageScale, ImageUnit);
  
  if x1 = x2 then begin                                   { line is vertical }
      MoveTo(x1 - LineSize, y1);
      LineTo(x1 + LineSize, y1);
      MoveTo(x2 - LineSize, y2);
      LineTo(x2 + LineSize, y2);
      
      MoveTo(x1, y1 - ArrowLen);
      LineTo(x1, y1);

      MoveTo(x1 - ArrowHead, y1 - ArrowHead);
      LineTo(x1, y1);
      MoveTo(x1 + ArrowHead, y1 - ArrowHead);
      LineTo(x1, y1);
      
      MoveTo(x2, y2 + ArrowLen);
      LineTo(x2, y2);

      MoveTo(x2 - ArrowHead, y2 + ArrowHead);
      LineTo(x2, y2);
      MoveTo(x2 + ArrowHead, y2 + ArrowHead);
      LineTo(x2, y2);
      
      d := (y2 - y1) / ImageScale;                   { label above top arrow }
      MoveTo(x2, y1 - LineSize - 20);
      
      SetText('Centered');
      Write(d : 4 : 1, ' ', ImageUnit);
    end

  else if y1 = y2 then begin                            { line is horizontal }
      MoveTo(x1, y1 - LineSize);
      LineTo(x1, y1 + LineSize);
      MoveTo(x2, y2 - LineSize);
      LineTo(x2, y2 + LineSize);
      
      MoveTo(x1 - ArrowLen, y1);
      LineTo(x1, y1);
      
      MoveTo(x1 - ArrowHead, y1 + ArrowHead);
      LineTo(x1, y1);
      MoveTo(x1 - ArrowHead, y1 - ArrowHead);
      LineTo(x1, y1);
      
      MoveTo(x2 + ArrowLen, y2);
      LineTo(x2, y2);
      
      MoveTo(x2 + ArrowHead, y2 + ArrowHead);
      LineTo(x2, y2);
      MoveTo(x2 + ArrowHead, y2 - ArrowHead);
      LineTo(x2, y2);
      
      d := (x2 - x1) / ImageScale;                 { label to right of arrow }
      MoveTo(x2 + LineSize + 15, y2);
      
      SetText('Left justified');
      Write(d : 4 : 1, ' ', ImageUnit);
    end

  else begin
      PutMessage('Line must be horizontal or vertical.');
      exit;
    end;

end;
